package icu.qx.gbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.gbs.domain.GbsGoodFile;
import icu.qx.gbs.service.IGbsGoodFileService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物品附件Controller
 *
 * @author yong
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/gbs/file")
public class GbsGoodFileController extends BaseController {
    @Autowired
    private IGbsGoodFileService gbsGoodFileService;

    /**
     * 查询物品附件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GbsGoodFile gbsGoodFile) {
        startPage();
        List<GbsGoodFile> list = gbsGoodFileService.selectGbsGoodFileList(gbsGoodFile);
        return getDataTable(list);
    }

    /**
     * 导出物品附件列表
     */
    @Log(title = "物品附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbsGoodFile gbsGoodFile) {
        List<GbsGoodFile> list = gbsGoodFileService.selectGbsGoodFileList(gbsGoodFile);
        ExcelUtil<GbsGoodFile> util = new ExcelUtil<GbsGoodFile>(GbsGoodFile.class);
        util.exportExcel(response, list, "物品附件数据");
    }

    /**
     * 获取物品附件详细信息
     */
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return success(gbsGoodFileService.selectGbsGoodFileByFileId(fileId));
    }

    /**
     * 新增物品附件
     */
    @Log(title = "物品附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbsGoodFile gbsGoodFile) {
        return toAjax(gbsGoodFileService.insertGbsGoodFile(gbsGoodFile));
    }

    /**
     * 新增物品附件
     */
    @Log(title = "物品附件", businessType = BusinessType.INSERT)
    @PostMapping("/list")
    public AjaxResult addList(@RequestBody List<GbsGoodFile> gbsGoodFiles) {
        return toAjax(gbsGoodFileService.insertGbsGoodFiles(gbsGoodFiles));
    }

    /**
     * 修改物品附件
     */
    @Log(title = "物品附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbsGoodFile gbsGoodFile) {
        return toAjax(gbsGoodFileService.updateGbsGoodFile(gbsGoodFile));
    }

    /**
     * 删除物品附件
     */
    @Log(title = "物品附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(gbsGoodFileService.deleteGbsGoodFileByFileIds(fileIds));
    }
}
